<?php
include_once("_common.php");
@include_once("$g4[path]/lib/mw.builder.lib.php");
include_once("$mw_cash[path]/cybercash.lib.php");

if (!$is_member) {
    //alert("로그인 후 이용해주세요.");

    $member[mb_nick] = "손";
}

set_session("cash_membership", false);

$g4[title] = $mw_smenu[ms_name];
include_once("_head.php");
?>
<script type="text/javascript" src="cybercash.js"></script>

<link rel="stylesheet" href="style.css" type="text/css"/>

<style type="text/css">
#cybercash-content { text-align:left; }
.block { margin-bottom:20px; padding:10px; border:5px solid #efefef; }
.btn1 { background-color:#efefef; cursor:pointer; }
.block-title { font-weight:bold; font-size:13px; margin:0 0 10px 0; }
.block-image { float:left; margin:0 10px 10px 0; }
.block-content { line-height:20px; margin:0 0 10px 0; padding:0 0 0 10px; width:700px; }
.block-content .stress { font-weight:bold; font-size:14px; margin:10px 0 10px 0; }
.block-content .blue { color:#0D6AB2; }
.block-hints { line-height:20px; padding:0 0 0 10px; width:600px; color:#888; }
.block-hints a { color:#888; }
.block-button { float:right; }
.btn-image { cursor:pointer; }

.data { width:100%; *width:95%; }
.my { background-color:#fffaca; }
.g { width:100%; *width:95%; height:15px; margin:0 auto 0 auto; background-color:#ccc; }
.g td { word-break:nowrap; font:normal 11px 'verdana'; color:#fff; }
.g td a { font:normal 11px 'verdana'; color:#fff; }
.gt { width:100%; *width:95%; }
.g1 { background-color:#f1899a; text-align:right; padding-right:5px; }
.g2 { background-color:#ccc; text-align:left; padding-left:5px; }
</style>

<div id="cybercash-content">

<div class="block-title"><img src="img/icon_cash.gif" align="absmiddle"> <?=$mw_cash[cf_cash_name]?> 소개</div>
<div class="block">
    <div class="block-content">
	마이위트(miwit.com) 안에서만 사용가능한 <strong><span class="blue">사이버캐쉬 (CyberCash)</span></strong> 입니다.
	싸이월드의 도토리를 생각하시면 이해가 쉽습니다.
	현재 <strong>배추패밀리 회원전용 게시판에서 <?=$mw_cash[cf_cash_name]?> 사용</strong>이 가능합니다.
	<?=$mw_cash[cf_cash_name]?> 충전은 사이트내 활동으로 쌓인 <strong>포인트를 이용해 변환</strong>이 가능하며
	포인트가 부족한 분은 현금 및 신용카드로 <?=$mw_cash[cf_cash_name]?> 충전이 가능합니다.
    </div>
    <!--<div class="block-content"> <strong><span class="blue">♡ <?=$mw_cash[cf_cash_name]?> 사용할 수 있는 곳</span></strong> </div>-->
    <div class="block-content">
	→ <a href="<?=$g4[bbs_path]?>/board.php?bo_table=g4_family">배추패밀리 회원전용 게시판 바로가기</a><br/>
	→ <a href="<?=$g4[path]?>/plugin/ad-pay/reg_form.php">마이위트 후원배너 등록하기</a><br/>
    </div>
    <? if ($mw_cash[cf_happybean]) { ?>
    <div class="block-hints"> ※ 판매금액의 <?=$mw_cash[cf_happybean]?>% 는 어려운 이웃을 돕는 해피빈에 기부됩니다. <a href="http://happybean.naver.com" target="_blank">[해피빈 바로가기]</a></div>
    <? } ?>
    <!--<div class="block-hints"> ※ 주의 : <?=$mw_cash[cf_cash_name]?> 충전 후 환불되지 않습니다.</div>-->
    <!--<div class="block-hints"> ※ 주의 : 솔루션 메뉴에서 판매하고 있는 프로그램은 <?=$mw_cash[cf_cash_name]?> 결제가 불가능하니 이점 유의해 주세요.</div>-->
</div>

<div class="block-title"><img src="img/icon_cash.gif" align="absmiddle"> <?=$mw_cash[cf_cash_name]?> 충전</div>
<div class="block">
    <div class="block-content">
	<div class="block-button">
	<? if ($mw_cash[cf_card]) { ?> <img src="img/bt_card.gif" class="btn-image" onclick="cash_charge('card')"> <? } ?>
	<? if ($mw_cash[cf_bank]) { ?> <img src="img/bt_bank.gif" class="btn-image" onclick="cash_charge('bank')"> <? } ?>
	<? if ($mw_cash[cf_hp]) { ?> <img src="img/bt_hp.gif" class="btn-image" onclick="cash_charge('hp')"> <? } ?>
	<? if ($mw_cash[cf_account]) { ?> <img src="img/bt_account.gif" class="btn-image" onclick="cash_charge('account')"> <? } ?>
	<? if ($mw_cash[cf_paypal]) { ?> <img src="img/bt_paypal.png" class="btn-image" onclick="cash_charge('paypal')"> <? } ?>
	</div>

	<div class="stress">현재 <?=$mw_cash[cf_cash_name]?> 소유 : <span class="blue"><?=number_format($mw_cash[mb_cash])?> <?=$mw_cash[cf_cash_unit]?></span></div>
    </div>
    <div class="block-hints"> ※ <?="$mw_cash[cf_cash_name] 1$mw_cash[cf_cash_unit]당 ".number_format(mw_get_payment($mw_cash[cf_cash_price], $mw_cash[cf_tax]))." 원"?>
	<? if ($mw_cash[cf_tax]) echo "(부가세 포함)"; ?>  입니다.</div>
    <? if ($mw_cash[cf_charge_min]) { ?>
    <div class="block-hints"> ※ 일반 최소충전금액은 <?=number_format(mw_get_payment($mw_cash[cf_charge_min], $mw_cash[cf_tax]))?> 원 <? if ($mw_cash[cf_tax]) echo "(부가세 포함)"; ?> 입니다.</div>
    <? } ?>

    <? if ($mw_cash[cf_card_min]) { ?>
    <div class="block-hints"> ※ 신용카드 최소충전금액은 <?=number_format(mw_get_payment($mw_cash[cf_card_min], $mw_cash[cf_tax]))?> 원 <? if ($mw_cash[cf_tax]) echo "(부가세 포함)"; ?> 입니다.</div>
    <? } ?>
</div>

<? if ($mw_cash[cf_point]) { ?>
<div class="block-title"><img src="img/icon_cash.gif" align="absmiddle"> 포인트→<?=$mw_cash[cf_cash_name]?> 전환</div>
<div class="block">
    <div class="block-content">
	<div class="block-button"> <img src="img/bt_point_to_cash.gif" onclick="point_to_cash()" class="btn-image"> </div>
	<div class="stress"><?=$member[mb_nick]?>님의 가용포인트 : <span class="blue"><?=number_format(mw_get_point_to_cash_possible())?> 점</span></div> 
    </div>
    <? if ($mw_cash[cf_possible_day]) { ?>
    <div class="block-hints"> ※ 가용포인트는 <?=$mw_cash[cf_possible_day]?>일 전까지 적립된 포인트를 의미합니다.</div>
    <? } ?>
    <? if ($mw_cash[cf_point_min]) {?>
    <div class="block-hints">※ <?=number_format($mw_cash[cf_point_min])?> 포인트 이상부터 전환 가능합니다.</div>
    <? } ?>
    <div class="block-hints"> ※ <?="$mw_cash[cf_cash_name] 1$mw_cash[cf_cash_unit] 당 포인트 ".number_format($mw_cash[cf_cash_point])." 점"?> 입니다.</div>
    <? if ($mw_cash[cf_point_level]) { ?>
    <div class="block-hints"> ※ 회원권한 <?=$mw_cash[cf_point_level]?>레벨 부터 변환 가능합니다.</div>
    <? } ?>

    <? if (!$mw_cash[cf_cash_to_point]) { ?>
    <div class="block-hints"> ※ <?=$mw_cash[cf_cash_name]?>→포인트로는 전환되지 않습니다. </div>
    <? } ?>
</div>
<? } ?>

<? if ($mw_cash[cf_cash_to_point]) { ?>
<div class="block-title"><img src="img/icon_cash.gif" align="absmiddle"> <?=$mw_cash[cf_cash_name]?>→포인트 전환</div>
<div class="block">
    <div class="block-content">
	<div class="block-button"> <img src="img/bt_point_to_cash.gif" onclick="cash_to_point()" class="btn-image"> </div>
	<div class="stress">현재 <?=$mw_cash[cf_cash_name]?> 소유 : <span class="blue"><?=number_format($mw_cash[mb_cash])?> <?=$mw_cash[cf_cash_unit]?></span></div>
    </div>
    <? if ($mw_cash[cf_cash_to_point_level]) { ?>
    <div class="block-hints"> ※ 회원권한 <?=$mw_cash[cf_cash_to_point_level]?>레벨 부터 변환 가능합니다.</div>
    <? } ?>

</div>
<? } ?>

<!--
<div class="block-title"><img src="img/icon_cash.gif" align="absmiddle"> 무료충전소</div>
<div class="block">
포인트가 부족하신가요? 무료충전소를 이용해보세요. <a href="<?=$g4[bbs_path]?>/board.php?bo_table=ph_reward">[바로가기]</a>
</div>
-->

<div class="block-title">
    <div style="float:right; padding:10px 10px 0 0;"><a href="cash-list.php" style="font:normal 11px 'arial';">more</a></div>
    <img src="img/icon_cash.gif" align="absmiddle"> <?=$mw_cash[cf_cash_name]?> 최근이용내역
</div>
<div class="block">
<?
$sql = "select * from $mw_cash[cash_list_table] where mb_id = '$member[mb_id]' and cl_status = '1' order by cl_id desc limit 10";
$qry = sql_query($sql);
for ($i=0; $row=sql_fetch_array($qry); $i++) {
?>
<div style="height:22px;"> <?=date("Y년 m월 d일", strtotime($row[cl_datetime]))?> : <?=$row[cl_content]?> </div>
<? }
if ($i==0)
    echo "<div style='text-align:center; margin:20px 0 20px 0;'>사용내역이 없습니다.</div>";
?>
</div>

<?php
$mb_id = $member['mb_id'];
$grade = mw_cash_grade($mb_id);
$list = array();
$sql = "select * from {$mw_cash['grade_table']} where gd_use = '1' order by gd_cash desc, gd_period*-1 desc, gd_point_save desc";
$qry = sql_query($sql);
while ($row = sql_fetch_array($qry)) {
    $list[] = $row;
}
$list_count = count($list);

if ($list_count) {
?>
    <div class="block-title">
        <img src="img/icon_cash.gif" align="absmiddle"> 나의 등급
    </div>

    <div class="block">
    <table border=0 cellpadding=0 cellspacing=0 class=data>
    <colgroup width="100"/>
    <colgroup width=""/>
    <colgroup width="100"/>
    <colgroup width="100"/>
    <colgroup width="100"/>
    <tr>
        <td class="head"> 나의등급 </td>
        <td class="head"> 등급이름 </td>
        <td class="head"> 산정기간 </td>
        <td class="head"> 충전 <?php echo $mw_cash['cf_cash_name']?> </td>
        <td class="head"> 추가적립 </td>
    </tr>
    <?php for ($i=0, $m=count($list); $i<$m; ++$i) { ?>
    <?php
    if ($row['gd_period']) {
        $gd_period = $row['gd_period'].'일';
    }
    else {
        $gd_period = "전체";
    }
    $my_grade = "-";
    $my_class = "";
    if ($grade['gd_id'] && $list[$i]['gd_id'] == $grade['gd_id']) {
        $my_grade = "○";
        $my_class = "my";
    }
    $gd_point_save = "-";
    if ($list[$i]['gd_point_save'])
        $gd_point_save = $list[$i]['gd_point_save'] . "%";
    ?>
    <tr class="<?php echo $my_class?>">
        <td class="body"> <?php echo $my_grade?> </td>
        <td class="body"> <?php echo $list[$i]['gd_name']?> </td>
        <td class="body"> <?php echo $gd_period?> </td>
        <td class="body"> <?php echo number_format($list[$i]['gd_cash']).$mw_cash['cf_cash_unit']." 이상"?> </td>
        <td class="body"> <?php echo $gd_point_save?> </td>
    </tr>
    <?php } ?>
    </table>

    <?php
    if ($is_member) {
        //$grade['my_charge'] = 100;
        $min = $grade['my_charge'] - $grade['gd_cash'];
        $max = $grade['next']['gd_cash'] - $grade['gd_cash'];
        $g1 = @round($min / $max, 2) * 100;
        $g2 = 100 - $g1;

        $s1 = "{$grade['gd_name']} (".number_format($grade['gd_cash']).")";
        $s2 = "{$grade['next']['gd_name']} (".number_format($grade['next']['gd_cash']).")";

        if (!$grade['gd_name'])
            $s1 = "시작";
    ?>
        <table border="0" cellpadding="0" cellspacing="0" class="gt">
        <tr>
            <td width="<?php echo $g1?>%" style="white-space:nowrap;"><?php echo $s1?></td>
            <!--<td style="white-space:nowrap;">현재 (<?php echo number_format($grade['my_charge'])?>)</td>-->
            <td width="<?php echo $g2?>%" style="white-space:nowrap; text-align:right;"><?php echo $s2?></td>
        </tr>
        </table> 
        <table border="0" cellpadding="0" cellspacing="0" class="g">
        <tr>
            <?php if ($g1) { ?>
            <td width="<?php echo $g1?>%" class="g1"><?php if ($g1 >= 30) echo number_format($grade['my_charge'])?></td>
            <?php } ?>
            <?php if ($g2) { ?>
            <td width="<?php echo $g2?>%" class="g2"><?php if ($g1 < 30) echo number_format($grade['my_charge'])?></td>
            <?php } ?>
        </tr>
        </table> 
    <?php } ?>
    </div>
<?php } // if ($list_count) ?>

</div>

<?
include_once("_tail.php");
